<?php
include_once XXF_RUNEXCEL;
class Wagset_ctl extends Ctl{
    function __construct(){
    }
    function main(array $xxfget) {
        $this::sessver();
        $type=!empty($_POST['type'])?$_POST['type']:false;
        $type=!empty($xxfget['type'])?$xxfget['type']:$type;
        if(!$type){
        	//$result=xdb::getInstance()->getarray("select * from xknv where xt like 'fangjian' or xt like 'xinfuxun'");
        	$this::show('wagset');
        }elseif($type=="downzxmb"){//中心工资单
            $re=new RunExcel();
            $re->createExcel();
            $re->createSheet();
            $array=array("序号","姓名","岗位工资","薪级工资","教师10%","保留津补贴","教龄","基础绩效","岗位绩效","其他绩效","扣绩效","通讯费","应付工资合计","个人所得税","养老保险","职业年金","医保及大额医疗费互助基金","失业保险","住房公积金","其他","实发金额","日期","备注");
            $re->setHeader($array);
            $re->down("中心工资模板".date("Ymd"));
        }elseif($type=="downxxmb"){//学校工资单，和上面是一样的，也就是说在职在编的工资模板是一样的
            $re=new RunExcel();
            $re->createExcel();
            $re->createSheet();
            $array=array("序号","姓名","岗位工资","薪级工资","教师10%","保留津补贴","教龄","基础绩效","岗位绩效","其他绩效","扣绩效","通讯费","应付工资合计","个人所得税","养老保险","职业年金","医保及大额医疗费互助基金","失业保险","住房公积金","其他","实发金额","日期","备注");
            $re->setHeader($array);
            $re->down("学校工资模板".date("Ymd"));
        }elseif($type=="downpymb"){//聘用工资单
            $re=new RunExcel();
            $re->createExcel();
            $re->createSheet();
            $array=array("序号","姓名","基本工资","管理岗位绩效","课时绩效","班主任绩效","其他绩效","扣绩效","保险补贴","通讯费","应付工资","个税","失业","医保","养老保险","实发金额","日期","备注");
            $re->setHeader($array);
            $re->down("聘用人员工资模板".date("Ymd"));
        }elseif($type=="upzx"){
            if (!empty($_FILES)) {
            	$tempFile = $_FILES['file']['tmp_name'];
            	$fileTypes = array('xls'); // File extensions
            	$fileParts = pathinfo($_FILES['file']['name']);
             	if (in_array($fileParts['extension'],$fileTypes)) {
            	    $re=new RunExcel();
            	    $re->fromExcel($tempFile);
            	    $bodyarray=$re->getSheetArray();
            	    $array=array("序号","姓名","岗位工资","薪级工资","教师10%","保留津补贴","教龄","基础绩效","岗位绩效","其他绩效","扣绩效","通讯费","应付工资合计","个人所得税","养老保险","职业年金","医保及大额医疗费互助基金","失业保险","住房公积金","其他","实发金额","日期","备注");
            	    for($i=0;$i<count($array);$i++){
            	        if($array[$i]!=$bodyarray[0][$i]){
            	            echo "上传失败，模板不符！";
            	            exit();
            	        }
            	    }
            	    $j=0;
            	    for($i=1;$i<count($bodyarray);$i++){
            	        if(strlen($bodyarray[$i][0])>0&&strlen($bodyarray[$i][1])>1&&strlen($bodyarray[$i][21])>5){
            	            $ar=array();
            	            $ar['wname']=$bodyarray[$i][1];
            	            $ar['gwgz']=$bodyarray[$i][2];
            	            $ar['xjgz']=$bodyarray[$i][3];
            	            $ar['js10']=$bodyarray[$i][4];
            	            $ar['bljbt']=$bodyarray[$i][5];
            	            $ar['jl']=$bodyarray[$i][6];
            	            $ar['jcjx']=$bodyarray[$i][7];
            	            $ar['gwjx']=$bodyarray[$i][8];
            	            $ar['qtjx']=$bodyarray[$i][9];
            	            $ar['kjx']=$bodyarray[$i][10];
            	            $ar['txf']=$bodyarray[$i][11];
            	            $ar['yfgzhj']=$bodyarray[$i][12];
            	            $ar['grsds']=$bodyarray[$i][13];
            	            $ar['ylbx']=$bodyarray[$i][14];
            	            $ar['zynj']=$bodyarray[$i][15];
            	            $ar['yb']=$bodyarray[$i][16];
            	            $ar['sybx']=$bodyarray[$i][17];
            	            $ar['zfgjj']=$bodyarray[$i][18];
            	            $ar['qt']=$bodyarray[$i][19];
            	            $ar['sf']=$bodyarray[$i][20];
            	            $ar['adate']=$bodyarray[$i][21];
            	            $ar['beizhu']=$bodyarray[$i][22];
            	            $ar2=array();
            	            $ar2['wname']=$bodyarray[$i][1];
            	            $ar2['adate']=$bodyarray[$i][21];
            	            xdb::getInstance()->indb("wages", $ar, $ar2);
            	            $j++;
            	        }
            	    }
            	    echo "上传成功！共处理".$j."条数据";
             	}else{
             	    echo "上传失败，文件类型不符！";
             	}
            }
        }elseif($type=="uppy"){
            if (!empty($_FILES)) {
            	$tempFile = $_FILES['file']['tmp_name'];
            	$fileTypes = array('xls'); // File extensions
            	$fileParts = pathinfo($_FILES['file']['name']);
             	if (in_array($fileParts['extension'],$fileTypes)) {
            	    $re=new RunExcel();
            	    $re->fromExcel($tempFile);
            	    $bodyarray=$re->getSheetArray();
            	    $array=array("序号","姓名","基本工资","管理岗位绩效","课时绩效","班主任绩效","其他绩效","扣绩效","保险补贴","通讯费","应付工资","个税","失业","医保","养老保险","实发金额","日期","备注");
                    for($i=0;$i<count($array);$i++){
            	        if($array[$i]!=$bodyarray[0][$i]){
            	            echo "上传失败，模板不符！";
            	            exit();
            	        }
            	    }
            	    $j=0;
            	    for($i=1;$i<count($bodyarray);$i++){
            	        if(strlen($bodyarray[$i][0])>0&&strlen($bodyarray[$i][1])>1&&strlen($bodyarray[$i][16])>5){
            	            $ar=array();
            	            $ar['wname']=$bodyarray[$i][1];
            	            $ar['jbgz']=$bodyarray[$i][2];
            	            $ar['glgwjx']=$bodyarray[$i][3];
            	            $ar['ksjx']=$bodyarray[$i][4];
            	            $ar['bzrjx']=$bodyarray[$i][5];
            	            $ar['qtjx']=$bodyarray[$i][6];
            	            $ar['kjx']=$bodyarray[$i][7];
            	            $ar['bxbt']=$bodyarray[$i][8];
            	            $ar['txf']=$bodyarray[$i][9];
            	            $ar['yfgzhj']=$bodyarray[$i][10];
            	            $ar['grsds']=$bodyarray[$i][11];
            	            $ar['sybx']=$bodyarray[$i][12];
            	            $ar['yb']=$bodyarray[$i][13];
            	            $ar['ylbx']=$bodyarray[$i][14];
            	            $ar['sf']=$bodyarray[$i][15];
            	            $ar['adate']=$bodyarray[$i][16];
            	            $ar['beizhu']=$bodyarray[$i][17];
            	            $ar2=array();
            	            $ar2['wname']=$bodyarray[$i][1];
            	            $ar2['adate']=$bodyarray[$i][16];
            	            xdb::getInstance()->indb("wages", $ar, $ar2);
            	            $j++;
            	        }
            	    }
            	    echo "上传成功！共处理".$j."条数据";
             	}else{
             	    echo "上传失败，文件类型不符！";
             	}
            }
        }elseif($type=="searchzx"){
            $result=xdb::getInstance()->getarray("select * from wages where jbgz is null");
            $this->show("wagshow",compact("result"));
        }elseif($type=="searchpy"){
            $result=xdb::getInstance()->getarray("select * from wages where jbgz <>''");
            $this->show("wagshowpy",compact("result"));
        }
    }
}